package com.atguigu.gmall.feign.search;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.search.fallback.SkuEsFeignClientFallBack;
import com.atguigu.gmall.model.list.Goods;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.list.SearchResponseVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 检错服务的远程客户端
 */
@FeignClient(value = "service-search",fallback = SkuEsFeignClientFallBack.class)
public interface SkuEsFeignClient {

    @PostMapping("es/sku/inner/onsale")
    Result saveSkuToEs(@RequestBody Goods goods);

    @PostMapping("/es/sku/inner/cancelSale/inner/{skuId}")
    Result delSkuToEs(@PathVariable("skuId") Long skuId);

    /**
     * feign:
     * 1、调用http://service-search/es/sku/search
     * 2、参数@RequestBody SearchParam searchParam,会转成json,放到请求体发给远程
     * 3、远程查到的数据，其实是json（map）,feign把json转发我们对应的返回值类型
     * @param searchParam
     * @return
     */
    @PostMapping("/es/sku/inner/search")
    Map<String,Object> searchGood(@RequestBody SearchParam searchParam);

    @GetMapping("/es/sku/inner/hotscore/{skuId}")
    Result updateSkuHotScore(@PathVariable("skuId") Long skuId,
                                    @RequestParam("hotScore") Long hotScore);
}
